<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if (! function_exists('collectingHtmlInput'))
{
	/**
	 * $object is array
	 * $except is array
	 */
    function collectingHtmlInput($objects=NULL, $excepts=NULL)
    {
    	$ci=& get_instance();	
    	$fieldNames=array();	
		
		// $cmf = $ci->em->getMetadataFactory();
		// $class = $cmf->getMetadataFor('models\entities\Berkas');
		// foreach ($class->associationMappings as $fieldMapping) {
		    // echo $fieldMapping['fieldName'] . "\n";
		// }
		// die('test');
		if ($objects != NULL){
    		if (is_array($objects)){
    			foreach ($objects as $object){
    				$objectNamespace = "models\\entities\\".$object;
					$cmf = $ci->em->getMetadataFactory();
					$class = $cmf->getMetadataFor($objectNamespace);
					
    				foreach ($class->fieldMappings as $field => $mapping){
    					if (!in_array($field, $excepts[$object])){
							$fieldNames[$object][$field] = $ci->input->post($object."_".$field);
						}
					}
					//print_r($class->associationMappings);
					foreach ($class->associationMappings as $field => $mapping){
						
						if (!in_array($field, $excepts[$object])){
							
							$fieldNames[$object][$field] = $ci->input->post($object."_".$field);
						}
					}
					//die('test');
    			}
			}
		}    	
		
        return $fieldNames;
    }   
}

if (! function_exists('getFiscalYear'))
{
	/** 
	 *  STATIC FISCAL YEAR
	 * 
	 */
	 
	 function getFiscalYear(){
	 	$year = array(2010,2011,2012,2013,2014,2015);
		return $year;
	 }
}

if (! function_exists('collectingHtmlInput'))
{
	/**
	 * $object is array
	 * $except is array
	 */
    function collectingHtmlInput($objects=NULL, $excepts=NULL)
    {
    	$ci=& get_instance();	
    	$fieldNames=array();	
		
		// $cmf = $ci->em->getMetadataFactory();
		// $class = $cmf->getMetadataFor('models\entities\Berkas');
		// foreach ($class->associationMappings as $fieldMapping) {
		    // echo $fieldMapping['fieldName'] . "\n";
		// }
		// die('test');
		if ($objects != NULL){
    		if (is_array($objects)){
    			foreach ($objects as $object){
    				$objectNamespace = "models\entities\\".$object;
					$cmf = $ci->em->getMetadataFactory();
					$class = $cmf->getMetadataFor($objectNamespace);
					
    				foreach ($class->fieldMappings as $field => $mapping){
    					if (!in_array($field, $excepts[$object])){
							$fieldNames[$object][$field] = $ci->input->post($object."_".$field);
						}
					}
					//print_r($class->associationMappings);
					foreach ($class->associationMappings as $field => $mapping){
						
						if (!in_array($field, $excepts[$object])){
							
							$fieldNames[$object][$field] = $ci->input->post($object."_".$field);
						}
					}
					//die('test');
    			}
			}
		}    	
		
        return $fieldNames;
    }   
}

if (! function_exists('isPermitt'))
{
	/** 
	 *  STATIC FISCAL YEAR
	 * 
	 */
	 
	 function isPermitt($userProfiles, $selectedProfileId){
	 	$isPermit = FALSE;
		
		foreach ($userProfiles as $up){
			if ($up->getProfile()->getId() == $selectedProfileId){
				$isPermit = TRUE;
				break;	
			}			
		}
		
		return $isPermit;
	 }
}

if (! function_exists('getCreateBerkasProsedurStep'))
{
	/** 
	 *  STATIC FISCAL YEAR
	 * 
	 */
	 
	 function getCreateBerkasProsedurStep($userProfiles, $procedureStep){
	 	$isPermit = FALSE;
		
		foreach ($userProfiles as $up){
			
			
		}
		
		return $isPermit;
	 }
}

if (! function_exists('isNewUploadFile'))
{
	/** 
	 *  STATIC FISCAL YEAR
	 * 
	 */
	 
	 function isNewUploadFile($files){
	 	$isNewFile = FALSE;
		
		if ($files['attach1']['error'] == 0 || $files['attach2']['error'] == 0 || $files['attach3']['error'] == 0
			|| $files['attach4']['error'] == 0 || $files['attach5']['error'] == 0){
			$isNewFile = TRUE;		
		}
		
		return $isNewFile;
	 }
}